package ws;

import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;

import javax.xml.namespace.QName;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
import javax.xml.ws.Dispatch;
import javax.xml.ws.Service;
import java.net.MalformedURLException;
import java.net.URL;

public class WsClient {

    public static void main(String[] args) throws Exception {
//        JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
//        factory.setServiceClass(HelloWorld.class);
//        factory.setAddress("http://localhost:9000/helloWorld");
//        HelloWorld client = (HelloWorld) factory.create();
//        String reply = client.sayHi("HI");
//        System.out.println("Server said: " + reply);


//        URL wsdlURL = new URL("http://localhost:9000/helloWorld?wsdl");
//        Service service = Service.create(wsdlURL, new QName("helloWorldService"));
//        Dispatch<Source> disp = service.createDispatch(new QName("HelloPort"), Source.class, Service.Mode.PAYLOAD);
//
//        Source request = new StreamSource("<hello/>");
//        Source response = disp.invoke(request);


        /*
        *
        * 如果是跟spring进行集成
        * <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:jaxws="http://cxf.apache.org/jaxws"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">

    <jaxws:client id="helloClient"
                  serviceClass="demo.spring.HelloWorld"
                  address="http://localhost:9002/HelloWorld" />
</beans>
        *
        * */
    }
}
